import Meta from "../components/Meta";
import Header from "../components/Header/Header";
import Nav from "../components/Nav/Nav";
import Banner from "../components/Home/Banner/Banner";
import GoodsList from "../components/Goods/List";
import GoodsListB from '../components/Goods/Listb';
import GoodsHeader from "../components/Goods/Header";
import Footer from "../components/Footer/Footer";
import { request } from "../utils/request";
import { transData } from "../utils/tool";
import AD from "../components/Ad/Ad";
import { Row, Col } from 'antd';
export default function Home(props) {

  return (
    <div>
      <Meta>
        <title>NINAMOKA-home</title>
        <link rel="icon" href="/favicon.ico" />
      </Meta>
      <Header navData={props.navData} />
      <Nav navData={props.navData} />
      <Banner data={props.bannerData} />
      <>
        <GoodsHeader data={props.confData[0]} />
        <GoodsList data={props.confData[0].goods} />
      </>
      <AD />
      <>
        <GoodsListB data={props.confData[1].goods} />
      </>


      {/* <GoodsHeader
        data={{
          title: "Our online shopes",
          hideSubtitle: true
        }}
      />
      <Row>
        <Col xs={1} md={2}></Col>
        <Col xs={22} md={20}>
          <Row gutter={8}>
            {props.channelData && props.channelData.map((item) => {
              return (
                <Col xs={12} md={6} key={item.name}>
                  <a href={item.url} target="_blank">
                    <img src={item.logoUrl} className="img-responsive" />
                  </a>
                </Col>
              );
            })}
          </Row>
        </Col>
        <Col xs={1} md={2}></Col>
      </Row> */}

      <Footer navData={props.navData} siteData={props.siteInfo}/>
    </div>
  );
}
export async function getServerSideProps(context) {
  const apiUrl = process.env.APIURL;
  console.log('apiurl', apiUrl)

  const navData = await request(`${apiUrl}/api/client/nav`);
  const bannerData = await request(`${apiUrl}/api/client/banner`);
  const newNavData = transData(navData.data, "id", "pid");
  const confData = await request(`${apiUrl}/api/client/homeGoods`);
  const channelData = await request(`${apiUrl}/api/client/getchannel`);
  const siteInfo = await request(`${apiUrl}/api/client/querySiteInfo`);
  const arr = [...channelData.data]
  console.log('navData',navData)
  for (let i = 0; i < 4 - channelData.data.length; i++) {
    arr.push({
      name: 'empty' + i,
      logoUrl: '/image/brand/empty.png'
    })
  }
  console.log('process env====', process.env.APIURL)
 
  return {
    props: {
      navData: newNavData,
      bannerData: bannerData.data,
      confData: confData.data,
      channelData: arr,
      siteInfo:siteInfo.data
    },
    // Re-generate the post at most once per second
    // if a request comes in
  };
}
